from django.db import models
from sorl.thumbnail import ImageField
from django import forms

# Create your models here.
class Type(models.Model):
    description = models.CharField(max_length=50)
    image = ImageField(upload_to="TypeImages", null=True, blank=True)

    def __unicode__(self):
        return self.description

    def get_absolute_url(self):
        return "/products/type/%s/" % self.id

class Fish(models.Model):
    name = models.CharField(max_length=50)
    description = models.CharField(max_length=300, blank=True)
    image = ImageField(upload_to="FishImages")

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return "/products/fish/%s/" % self.id

class Product(models.Model):
    name = models.CharField(max_length=50)
    description = models.CharField(max_length=300, blank=True)
    fish = models.ForeignKey(Fish, related_name="products")
    type = models.ForeignKey(Type, related_name="products")
    image = ImageField(upload_to="ProductImages", blank=True)

    class Meta:
        unique_together = ('fish', 'type',)

    def __unicode__(self):
        return self.name


class ProductDetail(models.Model):
    name = models.CharField(max_length=50)
    product = models.ForeignKey(Product, related_name="productDetails")
    size = models.CharField(max_length=20)
    boxSize = models.CharField(max_length=20)
    palletSize = models.CharField(max_length=20)

    def __unicode__(self):
        return self.name

class ProductImage(models.Model):
    product = models.ForeignKey(Product, related_name="images")
    description = models.CharField(max_length=100)
    image = ImageField(upload_to="ProductImages")

    def __unicode__(self):
        return self.description

class Staff(models.Model):
    name = models.CharField(max_length=100)
    position = models.CharField(max_length=50)
    email = models.EmailField()
    phone = models.CharField(max_length=100)
    image = ImageField(upload_to="StaffImages")

    def __unicode__(self):
        return self.name


class Url(models.Model):
    name = models.CharField(max_length=100)
    url = models.URLField(max_length=500)

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return self.url

class JobRequestModel(models.Model):
    name = models.CharField(max_length=100)
    ssn = models.IntegerField(max_length=10)
    phone = models.IntegerField(max_length=7)
    email = models.EmailField()
    message = models.CharField(max_length=300)

    def __unicode__(self):
        return self.subject

class JobRequest(forms.ModelForm):
    class Meta:
        model=JobRequestModel

